﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
namespace Miao.UI
{

    [SourcesPath("Assets/Plugins/miao-framework/UIPrefab/Toast.prefab")]
    public class Toast : UIPanel
    {
        public CanvasGroup bg;
        public TMPro.TMP_Text tmp_Text;
        public Vector2 initPos = new Vector2(0, 200);
        public float animationDuration = 1f;
        public float upY = 200;
        [NonSerialized]
        public string label;
        [NonSerialized]
        public float delayTime;
        [NonSerialized]
        public float fontSize;
        public void Play()
        {
            tmp_Text.text = label;
            tmp_Text.fontSize = fontSize;
            var rectTrans = GetComponent<RectTransform>();
            rectTrans.anchoredPosition = initPos;
            bg.alpha = 1;
            rectTrans.SetAsLastSibling();
            if (upY != 0)
            {
                rectTrans.DOAnchorPosY(rectTrans.anchoredPosition.y + upY, animationDuration).SetUpdate(true);
            }
            bg.DOFade(0, animationDuration).SetDelay(delayTime).OnComplete(() =>
            {
                //Destroy(this);
                Close();

            }).SetUpdate(true);
        }

    }
}

